package study06;

class Student2{
//    成员函数私有化
    private String name;
    private int age;

//    对私有属性进行封装
    String getName(){
        return name;
    }
    int setAge(){
        return age;
    }

//
    void setName(String n){
        name = n;
    }

    void setAge(int a){
        if(a < 0){
            System.out.println("设置的年龄不合法");
        }else{
            age = a;
        }
    }

    void speak(){
        System.out.println("我的名字是：" + name + "," + "今年" + age + "岁");
    }

}

/**
* @author GZQ
* @Date 2023/11/9
 */

public class Example03 {
    public static void main(String[] args) {
        Student2 stu = new Student2();
        stu.setAge(-30);
        stu.setName("小新");
        stu.setAge(19);
        stu.speak();
    }
}
